package com.d3works.apps.base.tracking;

import com.d3works.apps.base.db.GlobalTrackingLog;
import com.d3works.apps.base.db.GlobalTrackingLogLine;
import com.d3works.exception.service.TraceBackService;
import com.d3works.inject.Beans;
import com.d3works.meta.schema.actions.ActionView.ActionViewBuilder;
import com.d3works.rpc.ActionRequest;
import com.d3works.rpc.ActionResponse;

public class GlobalTrackingLogLineController {
  public void showGlobalTrackingLogLineReference(ActionRequest request, ActionResponse response) {
    try {
      GlobalTrackingLogLine globalTrackingLogLine =
          request.getContext().asType(GlobalTrackingLogLine.class);
      GlobalTrackingLog globalTrackingLog = globalTrackingLogLine.getGlobalTrackingLog();

      ActionViewBuilder actionViewBuilder =
          Beans.get(GlobalTrackingLogService.class).createReferenceView(globalTrackingLog);

      if (actionViewBuilder != null) {
        response.setView(actionViewBuilder.map());
      }
    } catch (Exception e) {
      TraceBackService.trace(response, e);
    }
  }
}
